package com.yilin.platform.controller.order;


import com.yilin.platform.base_core.application.BaseController;
import com.yilin.platform.base_core.application.PageData;
import com.yilin.platform.base_core.application.ReturnData;
import com.yilin.platform.base_core.commons.exception.BusinessException;
import com.yilin.platform.base_core.commons.utils.ParamUtil;
import com.yilin.platform.entity.order.LineOrder;
import com.yilin.platform.service.impl.order.LineOrderService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order/line/")
public class LineOrderController extends BaseController {

    @Resource
    private LineOrderService lineOrderService;
    /**
     * 保存修改普通线路
     */
    @PostMapping(value = "saveLineOrder")
    public ReturnData<Object> saveLineOrder(LineOrder lineOrder) {
        ParamUtil.isNull(lineOrder, "订单信息未传入");
        ParamUtil.isNull(lineOrder.getName(), "不能为空");
        ParamUtil.isNull(lineOrder.getSendName(), "发货商名称不能为空");
        ParamUtil.isNull(lineOrder.getSendAddress(), "发货商地址不能为空");
        ParamUtil.isNull(lineOrder.getPutName(), "收货商名称不能为空");
        ParamUtil.isNull(lineOrder.getPutName(), "收货商地址不能为空");
        lineOrderService.saveOrUpdateTineOrder(getLoginUser(), lineOrder);
        return jsonView(SUCCESS_CODE, "更新成功");
    }
    /**
     * 获取线路根据ID
     */
    @PostMapping(value = "getLineOrderById")
    public ReturnData<LineOrder> getLineOrderById(String lineOrderId) {
        ParamUtil.isNull(lineOrderId,"获取订单失败");
        LineOrder pageData = lineOrderService.getLineOrderById(lineOrderId);
        return jsonView(SUCCESS_CODE, "获取成功", pageData);
    }

    /**
     * 获取线路分页
     */
    @PostMapping(value = "getLineOrderPage")
    public ReturnData<PageData<LineOrder>> getLineOrderPage(LineOrder query, Integer page, Integer limit) {
        PageData<LineOrder> pageData = lineOrderService.getLineOrderPage(getLoginUser(), query, page, limit);
        return jsonView(SUCCESS_CODE, "获取成功", pageData);
    }

    /**
     * 删除线路
     */
    @PostMapping(value = "deleteLineOrder")
    public ReturnData<Object> deleteLineOrder(String lineOrderId) {
        ParamUtil.isNull(lineOrderId, "获取订单信息失败");
        lineOrderService.deleteLineOrder(lineOrderId);
        return jsonView(SUCCESS_CODE, "更新成功");
    }

}
